<?php

use Phinx\Migration\AbstractMigration;

class CreateDataSourceTable extends AbstractMigration
{

    public function up()
    {

        $table = $this->table('data_source', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '数据源表']);

        //添加数据字段
        $table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('key', 'string', ['default' => '', 'limit' => 128, 'comment' => '键'])
            ->addColumn('code', 'string', ['default' => '', 'limit' => 64, 'comment' => '编码'])
            ->addColumn('value', 'text', ['default' => null, 'comment' => '值'])
            ->addColumn('pid', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '父级id'])
            ->addColumn('created_by', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建者'])
            ->addColumn('created', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建时间'])
            ->addIndex(['key'], ['type' => 'unique', 'name' => 'idx_key']);



        //执行创建
        $table->create();
    }

    public function down()
    {
        $this->table("data_source")->drop()->save();
    }
}
